/**
 * 自动生成凭证 - 主界面
 * 
 * @author PSI
 * @copyright 2015 - present
 * @license GPL v3
 */
PCL.define("PSI.SLN0005.AutoVoucher.MainForm", {
  extend: "PSI.AFX.Form.MainForm",

  config: {
    permission: null
  },

  /**
   * @override
   */
  initComponent() {
    const me = this;

    PCL.apply(me, {
      items: [{
        tbar: me.getToolbarCmp(),
        id: me.buildId(me, "panelQueryCmp"),
        region: "north",
        height: 100,
        header: false,
        collapsible: true,
        collapseMode: "mini",
        border: 0,
        layout: {
          type: "table",
          columns: 5
        },
        bodyCls: "PSI-Query-Panel",
        items: me.getQueryCmp()
      }, {
        region: "center",
        border: 0,
        ...PSI.Const.BODY_PADDING,
        layout: "fit",
        bodyStyle: { borderWidth: 0 },
        border: 0,
        xtype: "tabpanel",
        items: [{
          title: "采购业务",
          border: 0,
          layout: "border",
          items: [{
            region: "north",
            border: 0,
            height: 40,
            layout: {
              type: "table",
              columns: 5
            },
            items: me.getPurchaseQueryCmp()
          }, {
            region: "center"
          }]
        }, {
          title: "销售业务",
          border: 0,
        }, {
          title: "存货业务",
          border: 0,
        }, {
          title: "固定资产",
          border: 0,
        }, {
          title: "职工薪酬",
          border: 0,
        }, {
          title: "存货期初建账",
          border: 0,
          layout: {
            type: "table",
            columns: 2
          },
          items: [
            { xtype: "container", colspan: 2, height: 50 },
            {
              xtype: "displayfield",
              margin: "5 0 0 10",
              value: "<h3>方式一：<span style='color:brown'>同步实施进销存模块和财务总账模块</span></h3>",
              colspan: 2,
            },
            {
              xtype: "displayfield",
              margin: "5 0 0 10",
              value: "<h3>由进销存模块的期初建账数据生成财务总账期初建账数据</h3>"
            },
            {
              xtype: "button",
              text: "打开 <strong>库存建账</strong> 模块",
              cls: "PSI-Query-btn1",
              width: 150,
              height: 26,
              margin: "5 0 0 10",
              handler: me._onOpenInitInv,
              scope: me
            },
            {
              xtype: "displayfield",
              margin: "5 0 0 10",
              value: "<hr />",
              width: 600,
              colspan: 2,
            },
            {
              xtype: "displayfield",
              margin: "5 0 0 10",
              value: "<h3>方式二：<span style='color:brown'>先实施进销存模块一段时间后，再实施财务总账模块</span></h3>",
              colspan: 2,
            },
            {
              xtype: "displayfield",
              margin: "5 0 0 10",
              value: "<h3>通过进销存模块中的库存账生成财务总账期初建账数据</h3>"
            },
            {
              xtype: "button",
              text: "打开 <strong>库存账查询</strong> 模块",
              cls: "PSI-Query-btn1",
              width: 150,
              height: 26,
              margin: "5 0 0 10",
              handler: me._onOpenInvQuery,
              scope: me
            },
          ]
        }]
      }]
    });

    me.callParent(arguments);

    me.editQueryOrg = PCL.getCmp(me.buildId(me, "editQueryOrg"));
  },

  /**
   * @private
   */
  getToolbarCmp() {
    const me = this;

    let result = [];
    let list = [];

    // 指南
    // 关闭
    if (result.length > 0) {
      result.push("-");
    }
    result.push({
      iconCls: "PSI-tb-help",
      text: "指南",
      ...PSI.Const.BTN_STYLE,
      handler() {
        me.focus();
        me.showInfo("TODO")
      }
    }, "-", {
      iconCls: "PSI-tb-close",
      text: "关闭",
      ...PSI.Const.BTN_STYLE,
      handler() {
        me.focus();
        me.closeWindow();
      }
    });

    result = result.concat(me.getShortcutCmp());

    return result;
  },

  /**
   * 快捷访问
   * 
   * @private
   */
  getShortcutCmp() {
    return ["->",
      {
        cls: "PSI-Shortcut-Cmp",
        labelWidth: 0,
        emptyText: "快捷访问",
        xtype: "psi_mainmenushortcutfield",
        width: 90
      }
    ];
  },

  /**
   * 查询条件
   * 
   * @private
   */
  getQueryCmp() {
    const me = this;

    const modelName = me.buildModelName(me, "QueryOrg");
    PCL.define(modelName, {
      extend: "PCL.data.Model",
      fields: ["id", "name"]
    });

    return [{
      xtype: "container",
      height: 26,
      html: `<h2 style='margin-left:20px;margin-top:18px;color:#595959;display:inline-block'>自动生成记账凭证</h2>
                &nbsp;&nbsp;<span style='color:#8c8c8c'>自动生成记账凭证，实现业财融合</span>
                <div style='float:right;display:inline-block;margin:10px 0px 0px 20px;border-left:1px solid #e5e6e8;height:40px'>&nbsp;</div>
                `
    }, {
      id: me.buildId(me, "editQueryOrg"),
      labelWidth: 70,
      width: 490,
      labelAlign: "right",
      labelSeparator: "",
      fieldLabel: "组织机构",
      margin: "10, 0, 0, 0",
      xtype: "combobox",
      queryMode: "local",
      editable: false,
      valueField: "id",
      displayField: "name",
      store: PCL.create("PCL.data.Store", {
        model: modelName,
        autoLoad: false,
        data: []
      }),
      listeners: {
        specialkey: {
          fn: me.__onEditSpecialKey,
          scope: me
        },
        select: {
          fn: me._onComboOrgSelect,
          scope: me
        },
      },
      colspan: 4,
    }, { xtype: "container" }, {
      xtype: "container",
      colspan: 2,
      items: [{
        xtype: "button",
        text: "查询",
        cls: "PSI-Query-btn1",
        width: 100,
        height: 26,
        margin: "5 0 0 10",
        handler: me._onQuery,
        scope: me
      }, {
        xtype: "button",
        text: "清空查询条件",
        cls: "PSI-Query-btn2",
        width: 100,
        height: 26,
        margin: "5, 0, 0, 10",
        handler: me._onClearQuery,
        scope: me
      }, {
        xtype: "button",
        text: "隐藏工具栏 <span class='PSI-shortcut-DS'>Alt + H</span>",
        cls: "PSI-Query-btn3",
        width: 140,
        height: 26,
        iconCls: "PSI-button-hide",
        margin: "5 0 0 20",
        handler() {
          // me.panelQueryCmp.collapse();
        },
        scope: me
      }]
    },];
  },

  /**
   * @private
   */
  getQueryParam() {
    const me = this;

    const result = {};

    return result;
  },

  /**
   * @private
   */
  _onOpenInitInv() {
    const me = this;

    me.focus();
    window.open(me.URL("Home/MainMenu/navigateTo/fid/2000"));
  },

  /**
   * @private
   */
  getPurchaseQueryCmp() {
    const me = this;

    return [{
      id: me.buildId(me, "editQueryPWBillStatus"),
      xtype: "combo",
      queryMode: "local",
      editable: false,
      valueField: "id",
      labelWidth: 50,
      labelAlign: "right",
      labelSeparator: "",
      fieldLabel: "状态",
      margin: "5, 0, 0, 0",
      store: PCL.create("PCL.data.ArrayStore", {
        fields: ["id", "text"],
        data: [[1, "货和发票都已到"], [2, "货已到，发票未到"],
        [3, "货未到，发票已到"]]
      }),
      value: 1,
    },];
  },

  /**
   * @private
   */
  _onOpenInvQuery() {
    const me = this;

    me.focus();
    window.open(me.URL("Home/MainMenu/navigateTo/fid/2003"));
  }
});
